<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="逾期平台" prop="overduePlatform">
        <el-input
          v-model="queryParams.overduePlatform"
          placeholder="请输入逾期平台"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="逾期金额" prop="overdueAmount">
        <el-input
          v-model="queryParams.overdueAmount"
          placeholder="请输入逾期金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="解决周期" prop="settlementPeriod">
        <el-input
          v-model="queryParams.settlementPeriod"
          placeholder="请输入解决周期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户姓名" prop="userName">
        <el-input
          v-model="queryParams.userName"
          placeholder="请输入用户姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['applet:overdueInfo:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="small"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['applet:overdueInfo:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="small"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['applet:overdueInfo:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="small"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['applet:overdueInfo:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="overdueInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <el-table-column label="用户头像" align="center" prop="avatar" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="逾期类型" align="center" prop="overdueType">
        <template #default="scope">
          <span v-if="scope.row.overdueType === 0">信用卡</span>
          <span v-else-if="scope.row.overdueType === 1">网贷</span>
          <span v-else>--</span>
        </template>
      </el-table-column>
      <el-table-column label="逾期平台" align="center" prop="overduePlatform" />
      <el-table-column label="逾期金额（元）" align="center" prop="overdueAmount" />
      <el-table-column label="解决周期（天）" align="center" prop="settlementPeriod" />
      <el-table-column label="处理方案" align="center" prop="treatmentPlan" />
      <el-table-column label="图1" align="center" prop="image1">
        <template slot-scope="scope">
          <image-preview :src="scope.row.image1" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="图2" align="center" prop="image2" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.image2" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="图3" align="center" prop="image3">
          <template slot-scope="scope">
          <image-preview :src="scope.row.image3" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="状态" align="center" prop="status" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['applet:overdueInfo:edit']"
          >修改</el-button>
          <el-button
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['applet:overdueInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改律所对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户头像URL" prop="avatar">
          <ImageUpload v-model="form.avatar" :limit="1" bizType="APPLETLOGO" type="cos" />
        </el-form-item>
        <el-form-item label="逾期平台" prop="overduePlatform">
          <el-input v-model="form.overduePlatform" placeholder="请输入逾期平台" />
        </el-form-item>
        <el-form-item label="逾期类型" prop="overdueType">
          <el-select v-model="form.overdueType" placeholder="请选择逾期类型" style="width: 100%">
            <el-option label="网贷" value="1" />
            <el-option label="信用卡" value="0" />
          </el-select>
        </el-form-item>
        <el-form-item label="逾期金额" prop="overdueAmount">
          <el-input v-model="form.overdueAmount" placeholder="请输入逾期金额" />
        </el-form-item>
        <el-form-item label="解决周期" prop="settlementPeriod">
          <el-input v-model="form.settlementPeriod" placeholder="请输入解决周期" />
        </el-form-item>
        <el-form-item label="处理方案" prop="treatmentPlan">
          <el-input v-model="form.treatmentPlan" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="图片1URL" prop="image1">
          <ImageUpload v-model="form.image1" :limit="1" bizType="APPLETLOGO" type="cos" />
        </el-form-item>
        <el-form-item label="图片2URL" prop="image2">
          <ImageUpload v-model="form.image2" :limit="1" bizType="APPLETLOGO" type="cos" />
        </el-form-item>
        <el-form-item label="图片3URL" prop="image3">
          <ImageUpload v-model="form.image3" :limit="1" bizType="APPLETLOGO" type="cos" />
        </el-form-item>
        <el-form-item label="用户姓名" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入用户姓名" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOverdueInfo, getOverdueInfo, delOverdueInfo, addOverdueInfo, updateOverdueInfo } from "@/api/applet/overdueInfo";

export default {
  name: "OverdueInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 律所表格数据
      overdueInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        avatar: null,
        overdueType: null,
        overduePlatform: null,
        overdueAmount: null,
        settlementPeriod: null,
        treatmentPlan: null,
        image1: null,
        image2: null,
        image3: null,
        userName: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        avatar: [
          { required: true, message: "用户头像URL不能为空", trigger: "blur" }
        ],
        overdueType: [
          { required: true, message: "逾期类型：0-信用卡，1-网贷不能为空", trigger: "change" }
        ],
        overduePlatform: [
          { required: true, message: "逾期平台不能为空", trigger: "blur" }
        ],
        overdueAmount: [
          { required: true, message: "逾期金额不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        userName: [
          { required: true, message: "用户姓名不能为空", trigger: "blur" }
        ],
        // status: [
        //   { required: true, message: "状态不能为空", trigger: "change" }
        // ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询律所列表 */
    getList() {
      this.loading = true;
      listOverdueInfo(this.queryParams).then(response => {
        this.overdueInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        avatar: null,
        overdueType: null,
        overduePlatform: null,
        overdueAmount: null,
        settlementPeriod: null,
        treatmentPlan: null,
        image1: null,
        image2: null,
        image3: null,
        createTime: null,
        updateTime: null,
        userName: null,
        status: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加律所";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOverdueInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改律所";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOverdueInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOverdueInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除律所编号为"' + ids + '"的数据项？').then(function() {
        return delOverdueInfo(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('applet/overdueInfo/export', {
        ...this.queryParams
      }, `overdueInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
